package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.ReservationVo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReservationMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Reservation record);

    int insertSelective(Reservation record);

    Reservation selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Reservation record);

    int updateByPrimaryKey(Reservation record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table reservation
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") java.util.List<Reservation> list);

    //查询指定用户在某个时间段内的取消次数
    @Select("select count(*) from reservation where update_time between #{begin} and #{end} and status = 2 and update_by = #{userId}")
    Integer countCancelledReservationsWithinTimeRange(LocalDateTime begin, LocalDateTime end, Long userId);

    List<ReservationVo> countByTime(String startTime, String endTime);

    Page<ReservationVo> pageList(Long id, Integer status);

    void cancel(Long id);
}